#include <stdio.h>
#include <gtk/gtk.h>

static void print_hello(GtkWidget *widget, gpointer data){

  g_print("Hello World\n");


}

static void activate(GtkApplication *app, gpointer user_data){

  GtkWidget *window = gtk_application_window_new(app);
  gtk_window_set_title(GTK_WINDOW(window), "Hello World");
  gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);

  GtkButtonBox *button_box = GTK_BUTTON_BOX(gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL));
  gtk_container_add(GTK_CONTAINER(window), (GtkWidget *) button_box);
  GtkButton *button = GTK_BUTTON(gtk_button_new_with_label("Hello World"));
  gtk_container_add(GTK_CONTAINER(button_box), (GtkWidget *) button);

  g_signal_connect(button,"clicked", G_CALLBACK(print_hello), NULL);

  // 关闭
  g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_close), window);

  // 显示
  gtk_widget_show_all(window);

}

int main(int argc, char **argv) {
  GtkApplication *app = gtk_application_new("test.app", G_APPLICATION_DEFAULT_FLAGS);
  g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);

  int status = g_application_run(G_APPLICATION(app) , argc, argv);

  g_object_unref(app);
  return status;
}
